import { usePunitStore } from '@/store';
import { getUrlParams } from '@/utils/qsUtil';
import type { PunitMapMeter } from '@/components/customize';

export interface QueryMeter extends PunitMapMeter { [key: string]: any };

export async function useRouteParams (change:(param:QueryMeter) => Promise<void>, numbers?: string[]) {

    const { GET_PUNIT_RECORD, getPunitRecord, showPunit } = usePunitStore();
    
    await showPunit(true); //显示项目

    const params = getUrlParams(numbers);

    const record = await GET_PUNIT_RECORD();

    const query = Object.assign({}, params, record);
    change(query);

    watch(() => getPunitRecord, (val) => {
        const query = Object.assign({}, params, val);
        change(query);
    }, { deep: true });
};